FROM debian:bullseye
MAINTAINER Andrey Volk <andrey@signalwire.com>

ARG PROXY_IP="192.168.31.183"

ENV http_proxy http://${PROXY_IP}:7890
ENV https_proxy http://${PROXY_IP}:7890
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -yq install apt-transport-https ca-certificates

ENV http_proxy ""
ENV https_proxy ""

COPY sources.list /etc/apt/sources.list
COPY entrypoint.sh /entrypoint.sh

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -yq install git

RUN git config --global http.proxy http://${PROXY_IP}:7890 \
    && git config --global https.proxy http://${PROXY_IP}:7890

RUN git clone https://github.com/signalwire/libks /usr/src/libs/libks \
    && git clone https://github.com/freeswitch/sofia-sip /usr/src/libs/sofia-sip \
    && git clone https://github.com/freeswitch/spandsp /usr/src/libs/spandsp \
    && git clone https://github.com/signalwire/signalwire-c /usr/src/libs/signalwire-c
#安装拓展工具
RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install \
    net-tools wget curl vim tcpdump tshark postgresql-client netcat

RUN DEBIAN_FRONTEND=noninteractive apt-get -yq install \
    # build
    build-essential cmake automake autoconf 'libtool-bin|libtool' pkg-config \
    # general
    libssl-dev zlib1g-dev libdb-dev unixodbc unixodbc-dev libncurses5-dev libexpat1-dev libgdbm-dev bison erlang-dev libtpl-dev libtiff5-dev uuid-dev \
    # core
    libpcre3-dev libedit-dev libsqlite3-dev libcurl4-openssl-dev nasm \
    # core codecs
    libogg-dev libspeex-dev libspeexdsp-dev \
    # mod_enum
    libldns-dev \
    # mod_python3
    python3-dev \
    # mod_av
    libavformat-dev libswscale-dev libavresample-dev \
    # mod_lua
    liblua5.2-dev \
    # mod_opus
    libopus-dev \
    # mod_pgsql
    libpq-dev \
    # mod_sndfile
    libsndfile1-dev libflac-dev libogg-dev libvorbis-dev \
    # mod_shout
    libshout3-dev libmpg123-dev libmp3lame-dev \
    #Postgres native support was added in FreeSWITCH 1.2.5.
    libpq-dev \
    #gdbserver
    openssh-server gdb gdbserver libwebsockets-dev valgrind

RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && yes root | passwd root

RUN cd /usr/src/libs/libks \
    #You need to either install libks or disable mod_verto in modules.conf
    && git checkout v1.8.3 \
    && cmake . -DCMAKE_INSTALL_PREFIX=/usr -DWITH_LIBBACKTRACE=1 && make install
RUN cd /usr/src/libs/sofia-sip && ./bootstrap.sh && ./configure CFLAGS="-g -ggdb" --with-pic --with-glib=no --without-doxygen --disable-stun --prefix=/usr && make -j`nproc --all` && make install
RUN cd /usr/src/libs/spandsp \
     #FreeSwitch 1.10.9 编译spandsp，V18_MODE_5BIT_4545错误
    && git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4 \
    && ./bootstrap.sh && ./configure CFLAGS="-g -ggdb" --with-pic --prefix=/usr && make -j`nproc --all` && make install
RUN cd /usr/src/libs/signalwire-c \
    #You need to either install signalwire-client-c or disable mod_signalwire in modules.conf
    && git checkout v1.3.3 \
    && PKG_CONFIG_PATH=/usr/lib/pkgconfig cmake . -DCMAKE_INSTALL_PREFIX=/usr && make install


# Cleanup the image
RUN apt-get clean
RUN git config --global --unset http.proxy \
    && git config --global --unset https.proxy

# Uncomment to cleanup even more
#RUN rm -rf /usr/src/*
ENTRYPOINT ["/entrypoint.sh"]